package com.zqx.manager.rpc;

import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import com.zqx.api.ProductRpc;
import com.zqx.api.domain.ParamInf;
import com.zqx.api.domain.ProductRpcReq;
import com.zqx.entity.Product;

import com.zqx.manager.service.ProductService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@AutoJsonRpcServiceImpl
@Service
@Slf4j
public class ProductRpcImpl  implements ProductRpc {

    @Autowired
    private ProductService productService;

    @Override
    public List<Product> query(ParamInf req) {
        //log.info("【查询多个产品】请求:{}",req);
        Pageable pageable = new PageRequest(0,1000, Sort.Direction.DESC,"rewardRate");
        //Pageable pageable = new PageRequest(req.getPage(), req.getPageSize(), req.getDirection(), req.getOrderBy());
        Page<Product> result = productService.query(req.getIdList(), req.getMinRewardRate(),
                req.getMaxRewardRate(), req.getStatusList(), pageable);
        //log.info("【查询多个产品】，返回结果为:{}",result);
        return result.getContent();
    }

    @Override
    public Product findOne(String id) {
        //log.info("【查询单个产品】,请求:{}",id);
        Product result = productService.findOne(id);
        //log.info("【查询单个产品】,返回结果:{}",result);
        return result;
    }
}
